﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace Chart.Net
{
    public class JqPlotBarChart : BarChart
    {
        public override string GetScripts()
        {
            return "<script src=\"../scripts/jqplot/plugins/jqplot.barRenderer.min.js\"></script>" +
            "<script src=\"../scripts/jqplot/plugins/jqplot.categoryAxisRenderer.min.js\"></script>" +
            "<script src=\"../scripts/jqplot/plugins/jqplot.pointLabels.min.js\"></script>" +
            "<script src=\"../scripts/jqplot/jqplot-bar.js\"></script>";
        }

        public override string GetBody()
        {
            StringBuilder result = new StringBuilder();
            string chartId = string.IsNullOrEmpty(Title) ? "untitled" : Title.Replace(' ', '-');
            string json = new JavaScriptSerializer().Serialize(barCollection);
            string template = Utility.ReadTemplate(Constants.TemplateJqPlotBar);
            result.AppendFormat(template, Title, chartId, json);
            return result.ToString();
        }
    }
}
